import user.User;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.regex.Pattern.*;

public class RegisterMain {
    /**
     * 注册
     * @param args
     */
    public static void main(String[] args) {
        User u=new User();
        while (true){
            System.out.println("请输入用户名");
            String user=u.input();
            Pattern regular = compile("^[a-zA-Z][a-zA-Z0-9_]{4,15}$");
            boolean flag=judge(user,regular);
            if (flag){
                System.out.println("可以使用");
                u.setAccount(user);
                break;
            }else{
                System.out.println("格式错误，请重新输入");
            }
        }
        while (true){
            System.out.println("请输入密码");
            String psw=u.input();
            Pattern regular = compile("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,}$");
            boolean flag=judge(psw,regular);
            if (flag){
                System.out.println("可以使用");
                System.out.println("请再次输入密码");
                String psws=u.input();
                if (psws.equals(psw)){
                    u.setPassword(psw);
                    break;
                }else{
                    System.out.println("密码不一致");
                }
            }else{
                System.out.println("格式错误，请重新输入");
            }
        }
        while (true){
            System.out.println("请输入邮箱");
            String eMail=u.input();
            Pattern regular = compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
            boolean flag=judge(eMail,regular);
            if (flag){
                System.out.println("可以使用");
                u.seteMail(eMail);
                System.out.println("恭喜，注册成功");
                break;
            }else{
                System.out.println("格式错误，请重新输入");
            }
        }
    }
    //判断方法
    public static boolean judge(String input,Pattern regular){
        Matcher flag=regular.matcher(input);
        return flag.matches();
    }
}
